package tech.heptagram.staff.config;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import java.util.ArrayList;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author wang.yuchuan
 * @date 2018/7/13
 */
@Configuration
@EnableSwagger2
@EnableAutoConfiguration
@Profile({"dev", "local"})//在生产环境不开启
public class Swagger2Config {

    @Bean
    public Docket createRestApi() {
        ArrayList<SecurityScheme> auth = new ArrayList<SecurityScheme>(1);
        auth.add(new ApiKey("Authorization", "", "header"));

        return new Docket(DocumentationType.SWAGGER_2)
//            .securitySchemes(auth)
            .apiInfo(apiInfo())
            .select()
            .apis(RequestHandlerSelectors.basePackage("tech.heptagram.staff.api"))
            .paths(PathSelectors.any())
            .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("StaffApi 系统基石API")
            .description("StaffApi 系统基石API接口模拟工具")
            .contact(new Contact("自来也", "https://staff.dev.intranet.heptagram.tech/staffapi", "wangyuchuan@zhongfl.com"))
            .version("1.0")
            .build();
    }
}
